<?php
namespace View;

class RegisterView {
	
	private $newUsername = "newUsername";
	private $firstName = "firstName";
	private $lastName = "lastName";
	private $socNr = "socNr";
	private $address = "address";
	private $address2 = "address2";
	private $zip = "zip";
	private $town = "town";
	private $phone = "phone";
	private $email = "email";			
	private $newPassword = "newPassword";
	private $newPassword2 = "newPassword2";
	private $Register = "submitregister";


	CONST PASSWORD_ON_BOTH_WRONG = 0;
	CONST FIELDS_EMPTY = 1;
	CONST USERNAME_IN_USE = 2;
	CONST PASSWORD_WRONG_FORMAT = 3;
	CONST REG_SUCCESS = 4;

	//returnerar registerformulär
	public function DoRegisterForm() {
		$xhtml = "
		<div class='post'>
		<h3>Registreringsformulär:</h3>
			<form action='' method='post' id='slick-login' autocomplete='on'> 
				<input placeholder='Användarnamn' value='' type='text' name='$this->newUsername' style='margin:5px' pattern='[a-z0-9_-]{3,15}' autofocus required  title='Användarnamnet måste vara minst 5 tecken!'/>
				<input placeholder='Förnamn' value='' type='text' name='$this->firstName' style='margin:5px' required/>
				<input placeholder='Efternamn' type='text' name='$this->lastName' style='margin:5px ' required/>
				<input placeholder='Personnr' type='text' name='$this->socNr' pattern='[1-2][0|9][0-9]{2}[0-1][0-9][0-3][0-9][-][0-9]{4}' style='margin:5px' required title='Ange ett giltigt personnummer såhär 19830101-xxxx'/> 
				<input placeholder='Adress' type='text' name='$this->address' style='margin:5px ' required/>
				<input placeholder='Adress 2' type='text' name='$this->address2' style='margin:5px ' />
				<input placeholder='Postnr' type='text' name='$this->zip' pattern='^(s-|S-){0,1}[0-9]{3}\s?[0-9]{2}' style='margin:5px;  width: 100px ' required  title='Ange ett giltigt postnummer ex. 39353 '/>
				<input placeholder='Ort' type='text' name='$this->town' style='margin:5px; width: 330px' required  title='Ange den stad du bor i!'/>
				<input placeholder='Telefonnr' type='tel' name='$this->phone' size='10' pattern='[0-9]{10}' style='margin:5px; width: 200px;' required title='Ange ett giltigt personnummer såhär 19830101-xxxx'/>
		 		<input placeholder='E-Mail' type='email' name='$this->email' style='margin:5px; width: 230px;' required/>
		 		<input placeholder='Lösenord' id='password' type='password' class='form-login' name='$this->newPassword' style='margin:5px' pattern='^.*(?=.{6,12})(?=.*\d)(?=.*[a-z]).*' required title='Lösenordet måste vara minst 6 tecken och innehålla minst ett nummer.'/>
		 		<input placeholder='Lösenord igen' id='passwordconf' type='password' class='form-login' name='$this->newPassword2' oninput='check(this)' style='margin:5px ' required/>
		 		<input type='submit' class='btn' name='$this->Register' value='Registera' style='margin:5px '/>
		 	</form>
		</div>";
		return $xhtml;
	}

	//Felmeddelanden
	public function TryRegMess($status)
	{
		switch ($status) {
			case self::PASSWORD_ON_BOTH_WRONG:
				return "<p class='error'><i>Lösernorden måste stämma överens i båda fälten.</i></p>";
				break;
			case self::FIELDS_EMPTY:
				return "<p class='info'><i>Alla fälten måste vara ifyllda.</i></p>";
				break;
			case self::USERNAME_IN_USE:
				return "<p class='info'><i>Användarnamnet är upptaget.</i></p>";
				break;
			case self::PASSWORD_WRONG_FORMAT:
				return "<p class='info'><i>Lösenordet måste vara minst 6 tecken och innehålla minst ett nummer.</i></p>";
				break;
			case self::REG_SUCCESS:
				return "<p class='success'><i>Registreringen lyckades.</i></p>";
				break;
			default:
			break;
		}
	
	}
	/**
	 * Funktioner för att hämta ut variabler
	 */
	public function GetUsername() {
		if (isset($_POST[$this->newUsername]) == false) {
			return null;
		}
		return $_POST[$this->newUsername];
	}
	
	public function GetFirstname() {
		if (isset($_POST[$this->firstName]) == false) {
			return null;
		}
		return $_POST[$this->firstName];
	}
	public function GetLastname() {
		if (isset($_POST[$this->lastName]) == false) {
			$_SESSION[$this->lastName] = $_POST[$this->lastName];
			return null;
		}
		return $_POST[$this->lastName];
	}
	public function GetSocnr() {
		if (isset($_POST[$this->socNr]) == false) {
			return null;
		}
		return $_POST[$this->socNr];
	}
	public function GetAddress() {
		if (isset($_POST[$this->address]) == false) {
			return null;
		}
		return $_POST[$this->address];
	}
	public function GetAddress2() {
		if (isset($_POST[$this->address2]) == false) {
			return null;
		}
		return $_POST[$this->address2];
	}
	public function GetZip() {
		if (isset($_POST[$this->zip]) == false) {
			return null;
		}
		return $_POST[$this->zip];
	}
	public function GetTown() {
		if (isset($_POST[$this->town]) == false) {
			$_SESSION[$this->town] = $_POST[$this->town];
			return null;
		}
		$_SESSION[$this->town] = $_POST[$this->town];
		return $_POST[$this->town];
	}
	public function GetPhone() {
		if (isset($_POST[$this->phone]) == false) {
			$_SESSION[$this->phone] = $_POST[$this->phone];
			return null;
		}
		$_SESSION[$this->phone] = $_POST[$this->phone];
		return $_POST[$this->phone];
	}
	public function GetEmail() {
		if (isset($_POST[$this->email]) == false) {
			$_SESSION[$this->email] = $_POST[$this->email];
			return null;
		}
		$_SESSION[$this->email] = $_POST[$this->email];
		return $_POST[$this->email];
	}
	
		//Hämtar lösenord
	public function GetPassword() {
		if (isset($_POST[$this->newPassword]) == false) {
			return null;
		}
		return $_POST[$this->newPassword];
	}
		//Hämtar lösenord 2
	public function GetPassword2() {
		if (isset($_POST[$this->newPassword2]) == false) {
			return null;
		}
		return $_POST[$this->newPassword2];
	}
	//kollar om man tryckt på registrera 
	public function TriedToRegister() {
		if (isset($_POST[$this->Register]) == false) {
			return false;
			 
		}
		
		return true;
		
	}
}